package com.ljxt.dt.web.servlet.basicinformationservlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ljxt.dt.domain.GoodsInfo;
import com.ljxt.dt.domain.SupplierType;
import com.ljxt.dt.service.basicinformationservice.SupplierListService;
import com.ljxt.dt.service.basicinformationservice.impl.SupplierListServiceImpl;
import com.ljxt.dt.vo.basicInformation.GoodsInfoVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 糖糖
 * @version 1.0.0
 * @date 2020/5/18 15:28
 * @copyright 老九学堂
 */
@WebServlet("/supplierDetail")
public class SupplierDetail extends HttpServlet {

    private SupplierListService supplierListService = new SupplierListServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("供应商详情的get请求");
        Map<String,Object> map = new HashMap<>();
        //获取供应商主键编号
        String id = req.getParameter("id");
        System.out.println("111111");
        map.put("id", id);
        System.out.println("222222");
        //根据供应商编号查找对应的供应商物品
        List<GoodsInfoVO> goodsInfoListVO =  supplierListService.findSupplierGoods(Integer.parseInt(id));
        System.out.println("------------------");
        for (GoodsInfoVO gg : goodsInfoListVO) {
            System.out.println(gg);
        }
        System.out.println("------------------");
        map.put("goodsList",goodsInfoListVO);
        //供应商类型名称
        String supplierType = req.getParameter("supplierType");
        map.put("supplierType", supplierType);

        //供应商名字
        String supplierName = req.getParameter("supplierName");
        map.put("supplierName", supplierName);
        //供应商详细地址
        String address = req.getParameter("address");
        map.put("address", address);
        //联系人名
        String contactName = req.getParameter("contactName");
        map.put("contactName", contactName);
        //联系电话
        String phone = req.getParameter("phone");
        map.put("phone", phone);

        System.out.println(id + "-" + supplierType + "-" + supplierName + "-" + address + "-" + contactName + "-" + phone);
        req.setAttribute("map",map);

        req.getRequestDispatcher("WEB-INF/views/basicinformation/supplierDetail.jsp").forward(req,resp);
    }


}
